/**
* \brief 
* \author pengcheng (pengcheng@yslrpch@126.com)
* \date 2020-05-23
* \attention CopyrightÃ‚Â©ADC Technology(tianjin)Co.Ltd
* \attention Refer to COPYRIGHT.txt for complete terms of copyright notice
*/

#ifndef CMW_APP_FRONT_VISION_H
#define CMW_APP_FRONT_VISION_H
#include <memory>
#include "cmw_app/sgm_app.h"
#include "cmw_app/detection_app.h"
#include "cmw_app/detection_centernet_app.h"
#include "detection_vision/impl/bbox2d.hpp"

namespace adc
{

class FrontVisionApp
{
public:

    using Ptr = std::shared_ptr<FrontVisionApp>;
    using ConstPtr = std::shared_ptr<const FrontVisionApp>;

    typedef std::vector<cv::Vec3b> PointColorType;
    typedef std::vector<cv::Point3f> PointCloudType;
    typedef detection::ImageBBox2D<float> ImageBBox2DType;
    typedef std::vector<ImageBBox2DType> ImageBBoxes2DType;
    typedef std::chrono::system_clock::time_point  TimeType;
    typedef cv::Mat PointCloudMat;

    typedef std::function<void(ImageBBoxes2DType&, TimeType&)> MarkGroundDetectionCallback;
    typedef std::function<void(ImageBBoxes2DType&, TimeType&)> CCTSDBDetectionCallback;
    typedef std::function<void(ImageBBoxes2DType&, cv::Mat&, TimeType&)> MarkGroundDetectionWithSrcCallback;
    typedef std::function<void(ImageBBoxes2DType&, cv::Mat&, TimeType&)> CCTSDBDetectionWithSrcCallback;
    typedef std::function<void(PointCloudMat&, TimeType&)> PointCloudMatCallback;
    typedef std::function<void(PointCloudType&, TimeType&)> PointCloudCallback;
    typedef std::function<void(PointColorType&, TimeType&)> PointColorCallback;
    typedef std::function<void(PointCloudType&,  PointColorType&, TimeType&)> PointAndColorCallback;

    typedef  std::shared_ptr<std::list<vector<Tn::Bbox>>> OutputDataType;

    typedef  cv::Mat ImageType;
    typedef std::vector<std::string> ClassNameType;
    typedef std::function<void(OutputDataType&, TimeType&, ImageType&, ClassNameType&)> DetectionCallback;

    enum TASK
    {
        STEREO = 1,
        OBSTACLE_DETECTION_YOLO,
        MARK_GROUND_DETECTION_CENTERNET,
        CCTSDB_DETECTION_CENTERNET
    };


    FrontVisionApp(){}
    FrontVisionApp(const std::string &left_camera_params);
    FrontVisionApp(const std::string &stereo_config_file, const std::string &detectiion_config_file , const std::string &mark_ground_config );
    void SetTask(std::string &config_file, TASK task, float hz = 10);
    
    void SetStereoPointCloudCallback(PointCloudCallback callback);
    void SetStereoPointColorCallback(PointColorCallback cakkback);
    void SetStereoPointAndColorCallback(PointAndColorCallback callback);
    void SetStereoPointCloudMatCallback(PointCloudMatCallback callback);

    void SetMarkGroundDetectionCallback(MarkGroundDetectionCallback callback);
    void SetMarkGroundDetectionWithImgCallback(MarkGroundDetectionWithSrcCallback callback);

    void SetCCTSDBDetectionCallback(CCTSDBDetectionCallback callback);
    void SetCCTSDBDetectionWithImgCallback(CCTSDBDetectionWithSrcCallback callback);
    
    //txs
    void SetDetectionObjectCallback(DetectionCallback callback);
   //txs

    void SetImages(cv::Mat &left, cv::Mat &right,  TimeType &time);
    void SetImage(cv::Mat &img, TimeType &time);
   
    //txs
//    void SetImg(cv::Mat &left, TimeTypr&time);
    //txs

    void Ready();
private:
    void InitConfig(const std::string &stereo_config_file, const std::string &detection_config_fie, const std::string &mark_ground_config);

private:
    std::shared_ptr<adc::StereoSgmApp> stereo_app_ptr_;
    cv::Mat map_l_x_, map_l_y_;

    //txs
    std::shared_ptr<adc::DetectionApp> detection_app_ptr_;
    //txs
    adc::DetectionCenternet::Ptr mark_ground_detection_ptr_;
    adc::DetectionCenternet::Ptr cctsdb_detection_ptr_;
};


}
#endif
